package com.mall.web.controller.org.admin;

import com.mall.org.classes.domain.ClassDto;
import com.mall.org.classes.service.IClassesService;
import com.mall.common.annotation.Log;
import com.mall.common.core.controller.BaseController;
import com.mall.common.core.domain.AjaxResult;
import com.mall.common.core.page.TableDataInfo;
import com.mall.common.enums.BusinessType;
import com.mall.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 班级信息Controller
 * 
 * @author mall
 * @date 2024-05-04
 */
@RestController
@RequestMapping("/admin/org/classes")
public class AdminClassesController extends BaseController
{
    @Autowired
    private IClassesService classesService;

    /**
     * 查询班级信息列表
     */
    @PreAuthorize("@ss.hasPermi('org:classes:list')")
    @GetMapping("/list")
    public TableDataInfo list(ClassDto classes)
    {
        startPage();
        List<ClassDto> list = classesService.selectClassesList(classes);
        return getDataTable(list);
    }

    /**
     * 导出班级信息列表
     */
    @PreAuthorize("@ss.hasPermi('org:classes:export')")
    @Log(title = "班级信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ClassDto classes)
    {
        List<ClassDto> list = classesService.selectClassesList(classes);
        ExcelUtil<ClassDto> util = new ExcelUtil<ClassDto>(ClassDto.class);
        util.exportExcel(response, list, "班级信息数据");
    }

    /**
     * 获取班级信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('org:classes:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(classesService.selectClassesById(id));
    }

    /**
     * 新增班级信息
     */
    @PreAuthorize("@ss.hasPermi('org:classes:add')")
    @Log(title = "班级信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ClassDto classes)
    {
        return toAjax(classesService.insertClasses(classes));
    }

    /**
     * 修改班级信息
     */
    @PreAuthorize("@ss.hasPermi('org:classes:edit')")
    @Log(title = "班级信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ClassDto classes)
    {
        return toAjax(classesService.updateClasses(classes));
    }

    /**
     * 删除班级信息
     */
    @PreAuthorize("@ss.hasPermi('org:classes:remove')")
    @Log(title = "班级信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(classesService.deleteClassesByIds(ids));
    }
}
